Add unit tests for PrepareAbiItems MSBuild task#11371
Closed
Copilot wants to merge 2 commits into
Closed
Conversation
8 tasks
Agent-Logs-Url: https://github.com/dotnet/android/sessions/2ef0252b-37ea-41b8-bccc-d6d3598eaf98 Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add unit tests for PrepareAbiItems MSBuild task
Add unit tests for May 15, 2026
PrepareAbiItems MSBuild task
Contributor
There was a problem hiding this comment.
Pull request overview
Adds NUnit coverage for the PrepareAbiItems MSBuild task’s mode→basename mapping, case-insensitive mode handling, and ABI-specific output item construction. This helps prevent regressions in how the task computes .ll source paths and abi metadata.
Changes:
- Introduces a new
PrepareAbiItemsTeststest fixture with parameterized cases for all supportedModevalues. - Adds tests for case-insensitive
Modematching and invalid mode error behavior. - Adds tests validating output item count,
ItemSpecpath construction, andabimetadata across single/multiple ABIs.
Comments suppressed due to low confidence (3)
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/PrepareAbiItemsTests.cs:56
- Same issue here: the expected ItemSpec is built with a hard-coded '/'. Since the task uses Path.Combine, construct the expected path with Path.Combine and use a case-insensitive comparison appropriate for paths.
Assert.IsTrue (task.Execute ());
Assert.IsNotNull (task.AssemblySources);
Assert.AreEqual (1, task.AssemblySources.Length);
Assert.AreEqual ($"/native/src/{expectedBase}.x86_64.ll", task.AssemblySources [0].ItemSpec);
}
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/PrepareAbiItemsTests.cs:89
- This test also assumes '/' separators in the produced ItemSpec. Use Path.Combine (NativeSourcesDir, $"typemaps.{abis[i]}.ll") (or similar) for expected values so the test passes cross-platform.
Assert.IsNotNull (task.AssemblySources);
Assert.AreEqual (abis.Length, task.AssemblySources.Length);
for (int i = 0; i < abis.Length; i++) {
Assert.AreEqual ($"/native/src/typemaps.{abis [i]}.ll", task.AssemblySources [i].ItemSpec);
Assert.AreEqual (abis [i], task.AssemblySources [i].GetMetadata ("abi"));
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/PrepareAbiItemsTests.cs:107
- Hard-coding the expected ItemSpec with '/' will be platform-dependent because PrepareAbiItems uses Path.Combine. Build the expected path with Path.Combine and compare using the same path comparison pattern used in other tests (e.g., StringAssert.AreEqualIgnoringCase).
Assert.IsNotNull (task.AssemblySources);
Assert.AreEqual (1, task.AssemblySources.Length);
Assert.AreEqual ("/output/environment.x86.ll", task.AssemblySources [0].ItemSpec);
Assert.AreEqual ("x86", task.AssemblySources [0].GetMetadata ("abi"));
Comment on lines
+29
to
+32
| Assert.IsNotNull (task.AssemblySources); | ||
| Assert.AreEqual (1, task.AssemblySources.Length); | ||
| Assert.AreEqual ($"/native/src/{expectedBase}.arm64-v8a.ll", task.AssemblySources [0].ItemSpec); | ||
| Assert.AreEqual ("arm64-v8a", task.AssemblySources [0].GetMetadata ("abi")); |
| @@ -0,0 +1,110 @@ | |||
| using NUnit.Framework; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
Comment on lines
+7
to
+11
| namespace Xamarin.Android.Build.Tests | ||
| { | ||
| [TestFixture] | ||
| public class PrepareAbiItemsTests : BaseTest | ||
| { |
| Debug = false, | ||
| }; | ||
| Assert.IsFalse (task.Execute ()); | ||
| Assert.AreEqual (1, errors.Count); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PrepareAbiItemshas no test coverage for its mode-to-basename mapping and ABI-specific path construction logic.Adds
PrepareAbiItemsTests.cswith 18 tests covering:[TestCase]parameterization (typemap→typemaps,environment→environment,compressed→compressed_assemblies,jniremap→jni_remap,marshal_methods→marshal_methods,runtime_linking→pinvoke_preserve,jni_init→jni_init_funcs)TypeMap,TYPEMAP,COMPRESSED, etc.)Execute()returnsfalseabimetadata for all 4 ABIs